{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "10c4e9fc-1af5-4edf-892a-ee041ea63a4c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "32890\n",
      "169\n",
      "29549\n",
      "154\n"
     ]
    }
   ],
   "source": [
    "import pickle as pkl\n",
    "import numpy as np\n",
    "import random\n",
    "\n",
    "### This is a deterministic script! \n",
    "\n",
    "with open(\"examplar_data_labels/LSVQ///labels_1080p.txt\") as f:\n",
    "    names = [(ele.split(\",\")[0]) for ele in f.readlines()][:2766]\n",
    "\n",
    "db = \"l1080p\"\n",
    "with open(f\"dover_predictions/val-{db}.pkl\",\"rb\") as f:\n",
    "    pr_labels = pkl.load(f)\n",
    "\n",
    "x = pr_labels[\"fragments\"][:2766] \n",
    "y = pr_labels[\"resize\"][:2766]\n",
    "\n",
    "\n",
    "\n",
    "x = np.array(x).reshape(1,-1)\n",
    "y = np.array(y).reshape(1,-1)\n",
    "\n",
    "xpair = x - x.T\n",
    "ypair = y - y.T\n",
    "\n",
    "unagreed = (xpair > 0.5) * (ypair < -0.5) * np.abs(xpair - ypair)\n",
    "\n",
    "pairs = []\n",
    "for i in range(2766):\n",
    "    for j in range(i+1, 2766):\n",
    "        if unagreed[i,j] > 1:\n",
    "            pairs.append((i,j))\n",
    "\n",
    "print(len(pairs))\n",
    "random.seed(42)\n",
    "rpais = random.sample(pairs, 100)\n",
    "npais = []\n",
    "all_indices = []\n",
    "for i,j in rpais:\n",
    "    npais.append((names[i], names[j]))\n",
    "    all_indices.append(i)\n",
    "    all_indices.append(j)\n",
    "    assert x[0,i] < x[0,j] and y[0,i] > y[0,j]\n",
    "all_indices = np.unique(all_indices)\n",
    "print(len(all_indices))\n",
    "sampled_names = list(np.array(names)[all_indices])\n",
    "\n",
    "with open(\"examplar_data_labels/LSVQ///labels_test.txt\") as f:\n",
    "    names = [(ele.split(\",\")[0]) for ele in f.readlines()][:3573]\n",
    "\n",
    "db = \"ltest\"\n",
    "with open(f\"dover_predictions/val-{db}.pkl\",\"rb\") as f:\n",
    "    pr_labels = pkl.load(f)\n",
    "\n",
    "x = pr_labels[\"fragments\"][:3573] \n",
    "y = pr_labels[\"resize\"][:3573]\n",
    "\n",
    "x = np.array(x).reshape(1,-1)\n",
    "y = np.array(y).reshape(1,-1)\n",
    "\n",
    "xpair = x - x.T\n",
    "ypair = y - y.T\n",
    "\n",
    "unagreed = (xpair > 0.5) * (ypair < -0.5) * np.abs(xpair - ypair)\n",
    "\n",
    "pairs = []\n",
    "for i in range(3573):\n",
    "    for j in range(i+1, 3573):\n",
    "        if unagreed[i,j] > 1:\n",
    "            pairs.append((i,j))\n",
    "\n",
    "random.seed(42)\n",
    "print(len(pairs))\n",
    "rpais2 = random.sample(pairs, 100)\n",
    "all_indices = []\n",
    "for i,j in rpais2:\n",
    "    npais.append((names[i], names[j]))\n",
    "    all_indices.append(i)\n",
    "    all_indices.append(j)\n",
    "    assert x[0,i] < x[0,j] and y[0,i] > y[0,j]\n",
    "all_indices = np.unique(all_indices)\n",
    "print(len(all_indices))\n",
    "sampled_names += list(np.array(names)[all_indices])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bcba4533-6d81-4cfc-a45e-bbf2fe7b0b27",
   "metadata": {},
   "source": [
    "After the script above, the `sampled_names` all the videos needed for blind subjective studies,\n",
    "`rpais, rpais2` are the 200 diverged pairs from LSVQ_test and LSVQ_1080p.\n",
    "\n",
    "The complete results for subjective studies will be released when the paper is accepted."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "GPU_Debug",
   "language": "python",
   "name": "pt1.8v"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
